﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace AjaxChatService.YahooMessenger
{
    public class LoginHelper
    {
        public static string GetRequestToken(string username, string password)
        {
            var getRequestTokenHelper = new GetRequestTokenHelper()
            {
                ConsumerKey = YMConstants.ConsumerKey,
                Username = username,
                Password = password
            };

            getRequestTokenHelper.ExecuteRequest();

            return getRequestTokenHelper.RequestToken;
        }

        public static YMAuthentication GetAccessToken(string requestToken)
        {
            var getAccessTokenHelper = new GetAccessTokenHelper()
            {
                ConsumerKey = YMConstants.ConsumerKey,
                ConsummerSecret = YMConstants.ConsumerSecret,
                Token = requestToken
            };

            getAccessTokenHelper.ExecuteRequest();

            return getAccessTokenHelper.AuthenticationToken;
        }

        public static string GetSessionId(YMAuthentication authenticationToken)
        {
            var getSessionHelper = new GetSessionHepler()
            {
                Authentication = authenticationToken
            };

            getSessionHelper.ExecuteRequest();
            return getSessionHelper.SessionId;
        }
    }
}